<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020-05-11
  Time: 7:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page isELIgnored="true" %>
<html>
<head>
    <title>商品类型</title>
    <%@include file="/comm/head.jsp"%>
</head>
<body>
<div id="root">
    <Collapse value="search">
        <Panel name="search">
            条件查询
            <p slot="content">
                <i-form inline :label-width="100">
                    <form-item label="商品类型名称:">
                        <i-input type="text" v-model="goodsTypeVo.goodsTypename"/>
                    </form-item>
<shiro:hasPermission name="splx:search">
                    <i-button type="primary"icon="ios-search" style="margin-left:20px" @click="pageNo=1;searchGoodsTypeList();">搜索</i-button>
</shiro:hasPermission>
                    <i-button type="success"icon="md-sync" @click="goodsTypeVo={};searchGoodsTypeList();pageNo=1"></i-button>
                </i-form>
            </p>
        </Panel>
    </Collapse>
    <card>
        <shiro:hasPermission name="splx:add">
            <i-button type="success" @click="toAdd"icon="md-add">添加商品类型</i-button>
        </shiro:hasPermission>
    </card>

    <i-table :columns="myColumns" :data="pageResult.rows" :height="300" border stripe @on-selection-change="tableSelection=arguments[0]">
        <template slot-scope="{ row,index }"  slot="action">
            <shiro:hasPermission name="splx:update">
                <i-button type="warning" @click="toUpdate(row)">修 改</i-button>
            </shiro:hasPermission>
            <shiro:hasPermission name="splx:del">
                <i-button type="error" @click="del(row,index)">删 除</i-button>
            </shiro:hasPermission>
        </template>

    </i-table>

    <modal v-model="updateFlag" title="修改商品类型" @on-ok="update">
        <i-form :label-width="80" style="padding: 30px" >
            <form-item label="类型名称">
                <i-input v-model="goodsType.goodsTpname" size="large"/>
            </form-item>
        </i-form>
    </modal>
    <modal v-model="addFlag" title="添加商品类型" @on-ok="add">
        <i-form :label-width="80" style="padding: 30px" >
            <form-item label="类型名称">
                <i-input v-model="goodsType.goodsTpname" size="large"/>
            </form-item>
        </i-form>
    </modal>
    <Page :total="pageResult.total"
          :page-size="pageSize"
    <%-- :current.sync="pageNo"--%>
          @on-change="pageNo=arguments[0];searchGoodsTypeList();"
    <%-- @on-change="searchUserList"--%>
           show-sizer
          :page-size-opts="[5,10,15]"
    <%-- @on-page-size-change="changPageSize"--%>
          @on-page-size-change="pageSize=arguments[0];searchGoodsTypeList();"
    />
</div>
<script>
    new Vue({
        el:"#root",
        data:{
            myColumns:[
                //{type:"selection",width:60,align:"center"},
                {title:"编号",key:"id",align:"center"},
                {title:"类型名称",key: "goodsTpname",align:"center"},
                {title:"操作",slot:"action",align:"center"},
            ],
            pageResult:{
                rows:[],
                total:50,
            },
            myData:[],
            goodsType:{},
            goodsTypeVo:{},
            pageNo:1,
            pageSize:5,
            tableSelection:[],
            updateFlag:false,
            addFlag:false

        },
        mounted(){
       //     this.search();
            this.searchGoodsTypeList();
        },
        methods:{
            searchGoodsTypeList(){
                axios.get(`${ctx}/jibenxinxi/splx/search/${this.pageNo}/${this.pageSize}`,{params:this.goodsTypeVo})
                    .then(({data})=>{
                        this.pageResult=data.result;
                    });
            },
         /*   search(){
                axios.get(`${ctx}/jibenxinxi/splx/list`)
                    .then(({data})=>{
                        this.myData=data.result;
                    });
            },*/
            toUpdate(row){
                //this.role=row;
                Object.assign(this.goodsType,row);
                this.updateFlag=true;
            },
            update(){
                axios.post(`${ctx}/jibenxinxi/splx/update`,this.goodsType)
                    .then(({data})=>{
                        this.updateFlag=false;//关闭模态框
                        iview.Message.success({content:data.msg});
                        this.searchGoodsTypeList();
                    });
            },
            del(row,index){
                let _this=this;
                let flag= iview.Modal.confirm({
                    title:"您确实要删除么？",
                    content:"该操作不可逆，请谨慎操作。",
                    onOk(){
                        axios.get(`${ctx}/jibenxinxi/splx/del?id=${row.id}`)
                            .then(({data})=>{
                                iview.Message.success({content:data.msg});
                                //_this.search();
                                _this.pageResult.rows.splice(index,1);
                            });
                    }
                });
            },
            toAdd(){
                this.goodsType ={};
                this.addFlag=true;
            },
            add(){
                if(this.goodsType.goodsTpname==null){
                     return this.$Message.warning("商品类型不能为空!")
                }
                axios.post(`${ctx}/jibenxinxi/splx/add`,this.goodsType)
                    .then(({data})=>{
                        this.addFlag=false;//关闭模态框
                        iview.Message.success({content:data.msg});
                        this.searchGoodsTypeList();

                    });
            },
        }

    })
</script>
</body>
</html>
